<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td>
                        <input type="text" v-model="info.Name">
                    </td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="info.Pwd">
                    </td>
                </tr>
                <tr>
                    <td align="right">操作</td>
                    <td>
                        <input type="button" class="btn btn-primary" value="登录" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
import { useStore } from '@/stores/User';
const a=useStore();
const route=useRoute();
const router=useRouter();

let info:any=reactive({
    Name:'',
    Pwd:''
})
const login=()=>{
    if(info.Name=="")
{
    alert('用户名不能为空');
    return;
}
if(info.Pwd=="")
{
    alert('密码不能为空');
    return;
}
axios({
    url:'http://localhost:5130/api/Exams/Admin',
    method:'get',
    params:info
})
.then(res=>{
    if(res.data==-1)
{
    alert('密码错误');
    return;
}
else if(res.data==-2)
{
    alert('用户名错误');
    return;
}
else{
    a.userInfo=res.data;
    alert('登录成功');
    router.push('/loginShow');
}
})
.catch(err=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>